<template>
  <div>
    <div>
      <el-select v-model="methodName" placeholder="请选择">
        <el-option
          v-for="item in methodInfos"
          :key="item.methodName"
          :label="item.methodName"
          :value="item.methodName">
        </el-option>
      </el-select>
      <el-button type="primary" @click="testFunctionInvoke()">运行</el-button>

    </div>
    <el-divider> 请求体</el-divider>
    <el-input
      type="textarea"
      :rows="10"
      placeholder="请输入内容"
      v-model="requestData">
    </el-input>
    <el-divider> 响应体</el-divider>
    <el-input
      type="textarea"
      :rows="10"
      placeholder="请输入内容"
      v-model="responseData">
    </el-input>

  </div>
</template>

<script>
import {innerServiceInvoke} from "../../api/basisMG";

export default {
  data() {
    return {
      requestData: '[]',
      responseData: '[]',
      serviceInfo: {
        port: 10012,
        methods: '',
        ip: 'localhost',
        serviceGroup: '',
        id: 97,
        serviceName: 'com.qiall.oms.ability.FindDubboService',
        version: '1.0.0',
        applicationName: 'oms-server'
      },
      methodInfos: [{
        methodName: "findBuddoServiceByPage",
        paramTypes: ["com.qiall.oms.ability.request.FindDubboServiceRequestPage"],
        params: [{
          accessToken: '',
          applicationName: '',
          pageQuery: null
        }]
      }],
      methodName:'',
      requestBody:{
        requestService:'',
        requestMethod:'',
        serviceGroup:null,
        version:'1.0.0',
        requestData:''
      }
    }
  },
  created() {
    this.serviceInfo=JSON.parse(this.$route.query.data);
    this.methodInfos=JSON.parse(this.serviceInfo.methods);
    this.requestBody.requestService=this.serviceInfo.serviceName;
  },
  watch: {
    methodName(newName, oldName){
      for(let i = 0; i < this.methodInfos.length; i++){
        if(this.methodInfos[i].methodName==newName){
          this.requestData=JSON.stringify(this.methodInfos[i].params);
          this.requestBody.requestMethod=newName;
          break;
        }
      }
    }
  },
  methods:{
    testFunctionInvoke(){
      this.requestBody.requestData=this.requestData;
      innerServiceInvoke(this.requestBody).then(ret=>{
        this.responseData=JSON.stringify(ret);
      })
    }
  }
}
</script>

